<template>
  <el-table
    v-loading="isLoading"
    :data="dataSet"
    @selection-change="handleSelectionChange"
  >
    <el-table-column type="selection" width="55" align="center" />
    <template v-for="column in dataOpt">
      <dict-tag-column
        v-if="column.type === TABLE_COLUMN_TYPE.DICT_TAG"
        :key="column.prop"
        :column="column"
      ></dict-tag-column>
      <el-table-column
        v-else
        :key="column.prop"
        :label="column.label"
        :align="column.align || 'center'"
        :prop="column.prop"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span v-if="column.filter">{{ column.filter(scope.row[column.prop]) }}</span>
          <span v-else>{{ scope.row[column.prop] }}</span>
        </template>
      </el-table-column>
    </template>
    <el-table-column
      label="操作"
      align="center"
      class-name="small-padding fixed-width"
    >
      <template slot-scope="scope">
        <el-button
          v-if="auth.edit"
          size="mini"
          type="text"
          icon="el-icon-edit"
          @click="handleUpdate(scope.row)"
          v-hasPermi="auth.edit"
          >修改</el-button
        >
        <el-button
          v-if="auth.del"
          size="mini"
          type="text"
          icon="el-icon-delete"
          @click="handleDelete(scope.row)"
          v-hasPermi="auth.del"
          >删除</el-button
        >
        <slot name="btn"></slot>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import DictTagColumn from "./DictTagColumn.vue";
import { TABLE_COLUMN_TYPE } from "./data";
export default {
  name: "SystemTable",
  components: { DictTagColumn },
  props: {
    dataSet: {
      type: Array,
      default: () => [],
    },
    dataOpt: {
      type: Array,
      default: () => [],
    },
    isLoading: Boolean,
    auth: {
      type: Object,
      default: () => {
        return {
          edit: false,
          del: false,
        };
      },
    },
  },
  data() {
    return {
      TABLE_COLUMN_TYPE,
    };
  },
  methods: {
    handleSelectionChange(selection) {
      this.$emit("selectionChange", selection);
    },
    handleUpdate(rowData) {
      this.$emit("edit", rowData);
    },
    handleDelete(rowData) {
      this.$emit("del", rowData);
    },
  },
};
</script>

<style lang="scss" scoped></style>
